layui.use('table', function () {
    var table = layui.table;
    //监听表格复选框选择
    table.on('checkbox(list)', function (obj) {
        console.log(obj)
    });
    //监听工具条
    table.on('tool(list)', function (obj) {
        var data = obj.data;
        if (obj.event === 'show') {
            layer.alert('查看行：<br>' + JSON.stringify(data))
        } else if (obj.event === 'del') {
            layer.confirm('真的删除行么', function (index) {
                obj.del();
                layer.close(index);
            });
        } else if (obj.event === 'edit') {
            layer.alert('编辑行：<br>' + JSON.stringify(data))
        }
    });

    var $ = layui.$, active = {
        getCheckData: function () { //获取选中数据
            var checkStatus = table.checkStatus('listTable')
                , data = checkStatus.data;
            if (data.length < 1) {
                layer.alert('请选择数据')
            } else {
                var ids = "";
                for (var i = 0; i < data.length; i++) {
                    ids += "ids=" + data[i].id + "&";
                }
                layer.alert('选中ID：<br>' + ids)
            }
        }
    };

    $('.listTable .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
});
 

 